<?php
include_once('common/header.php');
$objView   = Zend_Registry::get('objView');
$intType   = $objRequest->getParam('type', 0);
$objSearch = new Ecore_Search();
$arrJson   = null;
switch($intType) {
	case 1:						
		$dblLat    = $objRequest->getParam('lat', 0);
		$dblLng    = $objRequest->getParam('lng', 0);
		$intTotal  = 0;
		$arrResult = $objSearch->getMap($dblLat, $dblLng, $variable['MAP_RADIUS']['val'], $variable['MAP_TOP_LIMIT']['val'],$intTotal);
		include_once('map/template.php');
		$arrJson['results']   = $arrResult;
		break;
	case 2:
		$arrResult 	= Ecore_Function::json('map');
		include_once('map/template.php');
		$arrJson['results']			= $arrResult;
		break;
	case 3:		
		$intSearchType				= (int)$objRequest->getParam('kind', 0);
		$intSearchCategory			= (int)$objRequest->getParam('cate', 0);
		$strSearchProvince			= $objRequest->getParam('prov', '');
		$strSearchDistrict			= $objRequest->getParam('dist', '');
		$strSearchKeyword			= $objRequest->getParam('keyword', '');
		if($strSearchProvince != '' || $strSearchDistrict != '')
			$strSearchAddr			 = $strSearchKeyword;
		else
			$strSearchAddr			= '';
		if($strSearchProvince != '') {
			$strSearchAddr		   .= $strSearchAddr != '' ? (', ' . $strSearchProvince) : $strSearchProvince;
			$strSearchKeyword		= '';
		}
		if($strSearchDistrict != '') {
			$strSearchAddr		   .= $strSearchAddr != '' ? (', ' . $strSearchDistrict) : $strSearchDistrict;
			$strSearchKeyword		= '';
		}
		if($intSearchType == 0 && $intSearchCategory == 0 && $strSearchProvince == '' && $strSearchDistrict == '' && $strSearchKeyword == '') {
			$arrResult				= Ecore_Function::json('map');
		} else {			 
			$objSearch				= new Ecore_Search();
			$arrResult				= $objSearch->getAll(0, 100, 1, $intSearchType, $intSearchCategory, $strSearchAddr, $strSearchKeyword);
		}
		include_once('map/template.php');
		$arrJson['results']			= $arrResult;		
		break;
}
echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
exit();